import {Component, Input, ViewChild} from '@angular/core';
import {CommonPage} from '../common-page';
import {UserFormComponent} from './form/user.form.component';
import {DhlTableComponent} from '../../../shared/components/dhlcomponent/table/dhl-table.component';
import {DhlSwitchComponent} from '../../../shared/components/dhlcomponent/switch/dhl-switch.component';
import {DhlQueryLocationComponent} from '../../../shared/components/dhlcomponent/querylocation/dhl-query-location.component';
import {DhlTagComponent} from '../../../shared/components/dhlcomponent/tag/dhl-tag.component';
import {TagType} from '../../../shared/components/dhlcomponent/enums';

@Component({
  templateUrl: './user.component.html'
})
export class UserComponent extends CommonPage {

  formComponent = UserFormComponent;
  formTitle = `更新-{name}`;

  colWidths = [[5, 5, 5, 7]];
  status;
  name;
  userNo;
  viewComponent = {
    component: DhlTagComponent,
    initData: (row) => ({
      tagWidth: 65,
      text: row.available ? '启用' : '禁用',
      color: row.available ? TagType.GREEN : TagType.GREY
    })
  };
  adStatusComponent = {
    component: DhlTagComponent,
    initData: (row) => ({
      tagWidth: 65,
      text: row.adStatus,
      color: row.adStatus == '正常' ? TagType.GREEN : TagType.GREY
    })
  };

  adminView = {
    component: DhlSwitchComponent,
    initData: (row) => ({
      width: 40,
      value: row.isSuperManager,
      option: ['是', '否'],
      valueChange: ({rowData: {id}, value}) => {
        this.requestService.post(`account/updatesuper/${id}/${value}`).subscribe();
      }
    })
  };

  acctType
  acctTypes = [
    {
      name: 'Contractor',
      value: 'Contractor'
    }, {
      name: 'Employee',
      value: 'Employee'
    }, {
      name: 'Generic',
      value: 'Generic'
    }, {
      name: 'Operational',
      value: 'Operational'
    }, {
      name: 'SharedResource',
      value: 'SharedResource'
    }
  ]

  @Input() projectId;
  @ViewChild('table', {static: true, read: DhlTableComponent}) tableRef: DhlTableComponent;
  @ViewChild('queryCondition', {
    static: true,
    read: DhlQueryLocationComponent
  }) queryLocationRef: DhlQueryLocationComponent;


}




